new Vue({
    el: '#app',
    data: {
        defaultArea: window.localStorage.getItem('city_id'),
        area: window.localStorage.getItem('city_id'),
        cur: 0,
        curMetro: 0,
        community_id:document.getElementById('community_id').value,
        minPrice: '',
        maxPrice: '',
        room: [],
        rental_type: [],
        supporting: [],
        tags:[],
        floor: [],
        direction: [],
        renovation: [],
        year: '',
        minAcreage: '',
        maxAcreage: '',
        searchStatus: false,
        loading: false,
        proData: '',
        current: 1,
        pageSize: 10,
        total: 0,
        inregion: '',
        inunit: '',
        budget: '',
        mobile: '',
        sort: 'default',
        showTxt: '更多条件',
        showMore: true,
        showClass: '',
        send_loading: false
    },
    methods: {
        shorOrHide(){
            if (this.showMore){
                this.showClass = 'show'
                this.showMore = false
                this.showTxt = '收起条件'
            }else{
                this.showClass = ''
                this.showMore = true
                this.showTxt = '更多条件'
            }
        },
        getData(){
            if (this.loading) return
            this.loading = true
            if(parseInt(this.minPrice) > parseInt(this.maxPrice)){
                [this.minPrice,this.maxPrice] = [this.maxPrice,this.minPrice]
            }
            if(parseInt(this.minAcreage) > parseInt(this.maxAcreage)){
                [this.minAcreage,this.maxAcreage] = [this.maxAcreage,this.minAcreage]
            }
            var that = this
            var formData = {
                price:that.minPrice+'_'+that.maxPrice,
                acreage:that.minAcreage+'_'+that.maxAcreage,
                room:that.room,
                supporting:that.supporting,
                rental_type:that.rental_type,
                tags:that.tags,
                floor:that.floor,
                direction:that.direction,
                renovation:that.renovation,
                year:that.year,
                pagesize:that.pageSize,
                sort: that.sort,
                community_id: that.community_id,
            }
            axios.post(`/community/rental/data?page=${this.current}`,formData).then(function (response) {
                if(response.data.code === 0){
                    that.loading = false
                    that.searchStatus = true
                    that.proData = response.data.data.data
                    that.total = response.data.data.total
                }else{
                    that.$Message.error('数据获取失败，请稍后再试')
                }
            }).catch(function (error) {
                that.loading = false
            });
        },
        handleChangeSize(val) {
            this.pageSize = val
            this.$nextTick(() => {
                this.getData()
            })
        },
        changeSort(obj){
            this.sort = obj
            this.getData()
        },
        clearPrice(){
            this.minPrice = ''
            this.maxPrice = ''
            this.getData()
        },
        clearAcreage(){
            this.minAcreage = ''
            this.maxAcreage = ''
            this.getData()
        }
    },
    mounted() {
        this.getData()
    }
})